<?php
namespace Common\Model;

/**
 * 客栈表
 * @modify trainyao 2016-04-29 创建
 * @index  hotelId(`hotelentity_id`);
 */

Class HotelPayDetailModel extends BaseModel
{
    protected $trueTableName = 'bk_hotel_pay_detail';
    protected $field = 'id,hotelentity_id,type';

    /**
     * 如果没有客栈payDetail信息的情况下，要添加结算方式
     * @modify trainyao 2016-04-29 创建
     * @param  integer   $hotelId   客栈ID
     * @return mixin        执行成功返回id
     */
    public function addInfo($hotelId) {
        $data = array(
            'hotelentity_id' => $hotelId
        );
        $id = $this->add($data);
        return $id === false ? false : $id;
    }

    /**
     * 根据客栈获取payDetail信息
     * @modify trainyao 2016-04-29 创建
     * @param  integer   $hotelId   客栈ID
     * @return array              信息数组
     */
    public function getInfoByHotel($hotelId) {
        $option = array();
        if (is_array($hotelId)) {
            $hotelId = implode(',', $hotelId);
        }
        if (strpos($hotelId, ',') === false) {
            $option['hotelentity_id'] = $hotelId;
            $data = $this->where($option)->find();
        } else {
            $option['hotelentity_id'] = array('in', $hotelId);
            $data = $this->where($option)->select();
        }

        return empty($data) ? array() : $data;
    }

    /**
     * 更改该客栈的payDetail信息
     * @modify AmosZhong 2016-05-16 创建
     * @modify trainyao 2016-06-20 添加押金信息
     * @modify trainyao 2016-07-11 添加客栈支付类型
     * @modify wenhui 2017-05-04 增加国际手机检验
     * @param  integer   $hotelId   客栈ID
     * @param  string $hotelId       客栈Id
     * @param  string $refundRule    退订规则
     * @param  string $payMobile     支付短信通知号码
     * @param  string $accountMobile 结算短信号码
     * @param  string $accountType   账户类型
     * @param  string $bankName      开户行名称
     * @param  string $accountName   开户人姓名
     * @param  string $account       银行卡号
     * @param  string $deposit       客栈设置押金
     * @return boolean true为修改成功，false为修改失败
     */
    public function saveInfo($hotelId, $refundRule = null, $payMobile = null, $accountMobile = null, $accountType = null, $bankName = null, $accountName = null, $account = null, $deposit = null, $type = null, $payAreaCode = '86', $accountAreaCode = '86') {
        $option = array(
            'hotelentity_id' => $hotelId
        );
        $data = array();
        if (!is_null($refundRule)) {
            $data['refundrule'] = $refundRule;
        }
        if (!is_null($payMobile)) {
            $data['orderpaymobile'] = $payMobile;
        }
        if (!is_null($accountMobile)) {
            $data['accountmobile'] = $accountMobile;
        }
        if (!is_null($accountType)) {
            $data['accounttype'] = $accountType;
        }
        if (!is_null($bankName)) {
            $data['bankname'] = $bankName;
        }
        if (!is_null($accountName)) {
            $data['accountname'] = $accountName;
        }
        if (!is_null($account)) {
            $data['accountnumber'] = $account;
        }
        if (!is_null($deposit)) {
            $data['deposit'] = $deposit;
        }
        if (!is_null($type)) {
            $data['type'] = $type;
        }
        if (!is_null($payAreaCode)) {
            $data['payareacode'] = $payAreaCode;
        }
        if (!is_null($accountAreaCode)) {
            $data['accountareacode'] = $accountAreaCode;
        }

        return $this->where($option)->save($data) === false ? false : true;
    }
}
